NDPI_HOME=$(PWD)/../..
NDPI_BUILD="$(realpath ${NDPI_HOME}/packages/ubuntu)"

ndpi:
	$(RM) -r ./debian/ndpi-tmp ./debian/ndpi-dev-tmp ./debian/ndpi ./debian/ndpi-dev
	mkdir -p ./debian/ndpi-tmp ./debian/ndpi-dev-tmp
	mkdir -p  ./debian/ndpi-tmp/usr/lib ./debian/ndpi-tmp/usr/bin ./debian/ndpi-tmp/usr/share/ndpi
	mkdir -p ./debian/ndpi-dev-tmp/usr/lib ./debian/ndpi-dev-tmp/usr/include/ndpi ./debian/ndpi-dev-tmp/usr/lib/pkgconfig
	cd ${NDPI_HOME}; ./autogen.sh; ./configure; $(MAKE)
	cp $(NDPI_HOME)/src/lib/libndpi.so.@NDPI_VERS@ ./debian/ndpi-tmp/usr/lib/
	cp $(NDPI_HOME)/lists/public_suffix_list.dat ./debian/ndpi-tmp/usr/share/ndpi/
	cd ./debian/ndpi-tmp/usr/lib/; ln -s libndpi.so.@NDPI_VERS@ libndpi.so; cd -
	cd ./debian/ndpi-tmp/usr/lib/; ln -s libndpi.so.@NDPI_VERS@ libndpi.so.@MAJOR_RELEASE@; cd -
	cp $(NDPI_HOME)/src/lib/libndpi.a ./debian/ndpi-dev-tmp/usr/lib/
	cp $(NDPI_HOME)/example/ndpiReader ./debian/ndpi-tmp/usr/bin/
	cp $(NDPI_HOME)/src/include/*.h ./debian/ndpi-dev-tmp/usr/include/ndpi/
	cp $(NDPI_HOME)/libndpi.pc ./debian/ndpi-dev-tmp/usr/lib/pkgconfig/
	-$(RM) -r ./debian/ndpi-dev-tmp/usr/include/ndpi/ndpi_win32.h*
	@echo
	@find ./debian/ndpi-tmp -name "*~" -exec rm {} ';'
	@find ./debian/ndpi-dev-tmp -name "*~" -exec rm {} ';'
	dpkg-buildpackage -rfakeroot -d -us -uc
	@SIGN_CMD@ --sign builder -k D1EB60BE ../ndpi*deb
	@$(RM) ../ndpi*dsc ../ndpi*.gz ../ndpi*changes
	@/bin/mv ../ndpi*deb .
	@echo
	@echo "Package built."
	@/bin/ls ndpi*deb
	@echo "-------------------------------"
	-dpkg --contents ndpi_*.deb
	@echo "-------------------------------"
	@echo "-------------------------------"
	-dpkg --contents ndpi-dev_*.deb
	@echo "-------------------------------"

distclean:
	-cd ${NDPI_HOME} && $(MAKE) distclean

install:
	cd ${NDPI_HOME}; $(MAKE) install DESTDIR="${NDPI_BUILD}/debian/tmp" AM_UPDATE_INFO_DIR=no

clean:
	-cd ${NDPI_HOME} && $(MAKE) clean
	-$(RM) -r *~ *deb ./usr ./debian/ndpi ./debian/ndpi-dev ./debian/ndpi ./debian/ndpi-dev
